﻿using System;
using System.Collections.Generic;

namespace Pixels.Logic
{
    public enum Resource
    {
        Apples,
        Cogs,
        Antimatter,
        Max,
    };


    public class ResourcePool
    {
        private int[] _raw;
        public bool AllowNegatives = false;

        public ResourcePool() {
            this._raw = new int[(int)Resource.Max];
        }

        public void changeResource(Resource res, int amount) {
            this._raw[(int)res] += amount;
        }

        public bool hasEnough(ResourcePool cost) {
            for (Resource r = 0; r < Resource.Max; r++) {
                if (this[r] < cost[r]) return false;
            }
            return true;
        }

        public void subtractCost(ResourcePool cost) {
            if (!hasEnough(cost) && !AllowNegatives) throw new Exception("Cannot subtract! Cost too high");
            for (Resource r = 0; r < Resource.Max; r++) {
                changeResource(r, -cost[r]);
            }
        }

        public int this[Resource index]
	    {
            get { return _raw[(int)index]; }		    
	    }


    }
}
